﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AuditModel
{
    public class CandidateQuotaBL:ICandidateQuotaBL
    {
        #region ICandidateQuota Members
        private AuditDBEntities db;

        public CandidateQuotaBL()
        {
            db = new AuditDBEntities();
        }

        /// <summary>
        /// Set subjectID=0 to ignore this parameter; set countyCode="" to ignore it.
        /// </summary>
        /// <param name="annualEventId"></param>
        /// <param name="subjectID"></param>
        /// <param name="countyCode"></param>
        /// <returns></returns>
        public IEnumerable<CandidateQuota> GetCandidateQuotas(string annualEventId, int subjectID, string countyCode)
        {
            //throw new NotImplementedException();
            var r = (from t in db.CandidateQuotas
                     where t.AnnualEventID.Trim().ToLower().Contains(annualEventId.ToLower().Trim())
                     && (subjectID<=0 ? true : t.SubjectID == subjectID)
                     && (countyCode.Trim().Equals("")?true:countyCode.Trim()==t.CountyCode.Trim())
                     select t).ToList();

            return r;
        }

        #endregion

        #region ICandidateQuotaBL Members


        public List<sp_GetCandidateQuotas_Result> GetCandidateQuotas()
        {
            var r = (from t in db.sp_GetCandidateQuotas()           
                     select t).ToList();

            return r;
        }

        #endregion

        #region ICandidateQuotaBL Members

        /// <summary>
        /// Set subject=0 or countyCode="" to ignore.
        /// </summary>
        /// <param name="annualEvnetID"></param>
        /// <param name="subjectID"></param>
        /// <param name="countyCode"></param>
        /// <returns></returns>
        public List<sp_GetCandidateQuotas_Result> GetCandidateQuotasTotal(string annualEvnetID, int subjectID, string countyCode)
        {
            var r = (from t in this.GetCandidateQuotas()
                     where t.AnnualEventID == annualEvnetID
                     && (subjectID <= 0 ? true : t.SubjectID == subjectID)
                     && (countyCode.Trim().Equals("") ? true : countyCode.Trim() == t.CountyCode.Trim())
                     select t).ToList();
            return r;
        }

        #endregion

        #region ICandidateQuotaBL Members


        public List<sp_GetSubjectsProgressReport_Result> GetSubjectProgressReport(string annualEventID)
        {
            return db.sp_GetSubjectsProgressReport(annualEventID).ToList();
        }

        #endregion
    }
}
